473,498 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'ascii' codec can't encode character u'\xf3'

Hi, I get a piece of code of ogg123.py from the pyogg site, this is the
code:
*******************************
ogg_file = sys.argv[1]

vorbis_file=ogg.vorbis.VorbisFile(ogg_file)
comentarios = vorbis_file.comment()
recognized_comments = ('Artist', 'Album', 'Title', 'Version',
'Organization', 'Genre', 'Description',
'Date', 'Location', 'Copyright', 'Vendor')

comment_dict = {}
for com in recognized_comments:
comment_dict[string.upper(com)] = '%s: %%s' % com

known_keys = comment_dict.keys()

for key, val in comentarios.items():
if key in known_keys:
print comment_dict[key] % val
else:
continue
#print "Unknown comment: %s" % val
****************************

When I run int I get this error:

Album: Trapos
Vendor: Xiph.Org libVorbis I 20020717
Artist: Attaque 77
Traceback (most recent call last):
File "./ogg2sql.py", line 51, in ?
print comment_dict[key] % val
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in
position 15: ordinal not in range(128)
The title of the song has especial carateres Title= Perfección, it is in
espanish. I put at the begining og the scrpit the encodign coment

#!/usr/bin/env python
# -*- coding: UTF8 -*-
As you see the script get the comment og a vorbis file, and all the
comments are in unicode.

So I do not understan why the script uses an ascii codec, Am I not using
Unicode coding?
Jul 18 '05 #1
1 8106
oziko wrote:
So I do not understan why the script uses an ascii codec, Am I not using
Unicode coding?


The strings use Unicode, but they have to be encoded somehow to be
outputted. The default encoding is ASCII, which doesn't support all of
those fancy Unicode characters. Figure out what encoding your terminal
is expecting (probably utf-8) and encode all strings in that when
they're outputted or set a default encoding.
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
10668
by: Peter Wilkinson | last post by:
Hello tlistmembers, I am using the encoding function to convert unicode to ascii. At one point this code was working just fine, however, now it has broken. I am reading a text file that has is...
2
7660
by: jau | last post by:
Hi co-listers! I have been off Python for 2 years and now, that i'm used to Eclipse and Java, I decided to start a project with Python to refresh skills this time using Eclipse and TrueStudio....
3
20523
by: thomas Armstrong | last post by:
Hi Using Python 2.3.4 + Feedparser 3.3 (a library to parse XML documents) I'm trying to parse a UTF-8 document with special characters like acute-accent vowels: -------- <?xml version="1.0"...
24
8986
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
5
6164
by: Mike Currie | last post by:
Can anyone explain why I'm getting an ascii encoding error when I'm trying to write out using a UTF-8 encoder? Thanks Python 2.4.3 (#69, Mar 29 2006, 17:35:34) on win32 Type "help",...
19
3309
by: Thomas W | last post by:
I'm getting really annoyed with python in regards to unicode/ascii-encoding problems. The string below is the encoding of the norwegian word "fødselsdag". I stored the string as "fødselsdag"...
2
3310
by: John Nagle | last post by:
I'm trying to clean up a bad ASCII string, one read from a web page that is supposedly in the ASCII character set but has some characters above 127. And I get this: File...
4
5355
by: Oleg Parashchenko | last post by:
Hello, I'm working on an unicode-aware application. I like to use "print" to debug programs, but in this case it was nightmare. The most popular result of "print" was: UnicodeDecodeError:...
7
11127
by: luca72 | last post by:
hello i have this problem: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 8: ordinal not in range(128) Generally i solve the problem inserting : # -*- coding:...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.